/*
 * 英才汇硕信息科技有限公司 拥有本软件版权 2021 并保留所有权利。
 * Copyright 2021, YCHS Information&Science Techology Co.,Ltd,
 * All right reserved.
 */
package com.ychs.lawyerback.controller;

import com.ychs.lawyerback.annotation.RequiredPermission;
import com.ychs.lawyerback.common.R;
import com.ychs.lawyerback.dto.RoleOptDTO;
import com.ychs.lawyerback.dto.RoleQueryDTO;
import com.ychs.lawyerback.service.RoleService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author mayujing
 * @version 1.0
 */

@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;


    @GetMapping("/list")
    @RequiredPermission("system:role:list")
    public R<?> getRolesByCondition(RoleQueryDTO roleQueryDTO) {
        Map<String,Object> result = roleService.getRolesByCondition(roleQueryDTO);
        return R.success(result);
    }

    @PostMapping("/add")
    @RequiredPermission("system:role:add")
    public R<?> addRole(@Valid @RequestBody RoleOptDTO roleOptDTO) {
        int res = roleService.addRole(roleOptDTO);
        return res > 0 ? R.success() : R.fail();
    }

    @PutMapping("/edit")
    @RequiredPermission("system:role:edit")
    public R<?> updateRole(@Valid @RequestBody RoleOptDTO roleOptDTO) {
        int res = roleService.updateRole(roleOptDTO);
        return res > 0 ? R.success() : R.fail();
    }

    @DeleteMapping("/delete")
    @RequiredPermission("system:role:delete")
    public R<?> deleteRole(@RequestBody List<Long> ids) {
        int res = roleService.deleteRole(ids);
        return res > 0 ? R.success() : R.fail();
    }
}
